package com.clickpaas.workinghours.service.Impl;

import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.model.OpportunityDTO;
import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.model.OpportunityDTOPageInfoResponse;
import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.model.OpportunityDTOResponse;
import com.clickpaas.workinghours.dao.OpportunityDao;
import com.clickpaas.workinghours.entity.OpportunityEntity;
import com.clickpaas.workinghours.service.OpportunityService;
import com.clickpaas.workinghours.utils.DataInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class OpportunityServiceImpl implements OpportunityService {
    @Resource
    private OpportunityDao opportunityDao;

    /**
     * 获取数据
     *
     * @param entity
     * @return
     */
    @Override
    public List<OpportunityDTO> getDataInfo(OpportunityEntity entity) {
        List<OpportunityDTO> reList;
        try {
            if (null == entity || DataInfoUtil.isAllFieldNull(entity)){
                reList = DataInfoUtil.castListCopy(opportunityDao.queryDataInfo(), OpportunityDTOPageInfoResponse.class, OpportunityDTO.class);
            }else {
                reList = DataInfoUtil.castListCopy(opportunityDao.queryDataInfo(entity), OpportunityDTOResponse.class, OpportunityDTO.class);

            }
        } catch (Exception e) {
            log.info("入参对象异常,请检查：【{}】,报错信息：【{}】",entity,e);
            return null;
        }
        if (null != reList && reList.size()>0){
            return reList;
        }
        return null;
    }

    /**
     * 项目数据转换为bean
     *
     * @param list
     * @return
     */
    @Override
    public List<OpportunityEntity> DataConver(List<OpportunityDTO> list) {
        return DataInfoUtil.castListCopy(list,OpportunityDTO.class,OpportunityEntity.class);
    }
}
